//function init(thisform){
//	 var loginForm = document.loginForm;
//	 loginForm.action = "getRandomPictrue";
//	 return true;
//}

function validateForm(thisform){//普通用户登录
	
	with(thisform){
		
		var username = document.forms["loginForm"]["user.username"].value;
		var password = document.forms["loginForm"]["user.userpass"].value;
		
		if(checkName(username)==false){
			return false ;
		}else if(checkPassword(password)==false){
			return false ;
		}else{ 
			 document.getElementById('error').innerText="输入合法";
			 var loginForm = document.loginForm;
			 loginForm.action = "login";
			 loginForm.submit(); 
			 return true;
		}
	}
	 
}

function validateForm2(thisform){//普通用户注册
	
	with(thisform){
		
		var username = document.forms["registerForm"]["user.username"].value;
		var password = document.forms["registerForm"]["user.userpass"].value;
		var repass = document.forms["registerForm"]["repassword"].value;
		var email = document.forms["registerForm"]["user.useremail"].value;
		
		if(checkName(username)==false){
			return false ;
		}else if(checkPassword(password)==false||checkPassword(repass)==false){
			return false ;
		}else if(password != repass){
			document.getElementById('error').innerText="2次密码输入不一致";
			return false;
		}else if(password==username){
			document.getElementById('error').innerText="密码和用户名不能相同";
			return false;
		}else if(checkEmail(email)==false){
			return false;
		}else{ 
			document.getElementById('error').innerText="JavaScript检测成功";
			 var registerForm = document.registerForm;
			 registerForm.action = "register";
			 registerForm.submit(); 
			 return true;
		}
	}
	
}

function validateForm3(thisform){//管理员登录
with(thisform){
		
		var username = document.forms["loginForm"]["admin.adminuser"].value;
		var password = document.forms["loginForm"]["admin.adminpass"].value;
		
		if(checkName(username)==false){
			return false ;
		}else if(checkPassword(password)==false){
			return false ;
		}else{ 
			 document.getElementById('error').innerText="检查成功";
			 var loginForm = document.loginForm;
			 loginForm.action = "login";
			 loginForm.submit(); 
			 return true;
		}
	}
}

function checkName(username){
	
	var myReg = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;//特殊字符
	var hanzi = /[\u4E00-\u9FA5\uF900-\uFA2D]/;;//汉字
	
	if(username.length<6){
		document.getElementById('error').innerText="输入用户名长度过短";
		return false ;
	}else if(username.length>16){
		document.getElementById('error').innerText="输入用户名长度过长";
		return false;
	}else if(myReg.test(username)){
		document.getElementById('error').innerText="用户名不能包含特殊字符";
		return false;
	}else if(hanzi.test(username)){
		document.getElementById('error').innerText="用户名不能包含汉字";
		return false;
	}else if(username == null || username == "" || username == undefined){
		document.getElementById('error').innerText="用户名不能为空";
		return false;
	}else{
		return true;
	} 
		
}

function checkPassword(password){
	
 
	var num =  /^\+?[1-9][0-9]*$/;;//数字
	var zimu = /^[A-Za-z]+$/;//字母
	
	if(password.length<6){
		document.getElementById('error').innerText="输入密码长度过短";
		return false ;
	}else if(password.length>16){
		document.getElementById('error').innerText="输入密码长度过长";
		return false;
	}else if(password == null || password == "" || password == undefined){
		document.getElementById('error').innerText="密码不能为空";
		return false;
	}else if(num.test(password)){
		document.getElementById('error').innerText="密码不能全为数字";
		return false;
	}else if(zimu.test(password)){
		document.getElementById('error').innerText="密码不能全为字母";
		return false;
	}else
		return true;
	
}

function checkEmail(email){
	 
	var emailName = email.substring(0, email.indexOf("@"));
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(emailName.length<6){
		document.getElementById('error').innerText="输入邮箱名长度过短";
		return false ;
	}else if(emailName.length>16){
		document.getElementById('error').innerText="输入邮箱名长度过长";
		return false;
	}else if(!myreg.test(email)){
		document.getElementById('error').innerText="请输入正确的邮箱格式";
		return false;
	}
	else
		return true;
	
}

function isDisplayUser(is){//主页面/用户按钮
	
	//传过来的is是个字符串
	var user = document.getElementById("user");//用户操作
	var userLogin = document.getElementById("userLogin");//用户登录按钮
	var cart = document.getElementById("cartNum");
	 
	if( is == "null"  ){ 
		user.style.display = "none";
		cart.style.displya = "none";
		userLogin.style.display = "block"; 
	}else{ 
		user.style.display = "block";
		userLogin.style.display = "none";
		cart.style.display = "block";
	} 
	
}

function changeValidateCode(obj) {//获取当前的时间作为参数，无具体意义     
    //获取当前的时间作为参数，无具体意义     
 var timenow = new Date().getTime();     
 //每次请求需要一个不同的参数，否则可能会返回同样的验证码     
 //这和浏览器的缓存机制有关系，也可以把页面设置为不缓存，这样就不用这个参数了。     
 obj.src="getRandomPictrue?d="+timenow;   
}     
 